<?php

namespace application\controller\cp;

use application\service\CatelogService;
use application\entity\input\CatelogSearch;
use core\system\HttpRequest;
use core\entity\Criteria;
use application\util\TextUtil;
use core\entity\Page;
class CatelogController extends BaseController {

    private $catelogService;

    public function __construct() {
        parent::__construct();
        $this->view->layout = '/layout/main';
        $this->catelogService = new CatelogService();
    }

    /**
     * Danh sách danh mục
     * @mapping(value=cp/catelog.html)
     */
    public function grid() {
        $search = HttpRequest::getRequest(CatelogSearch::class);
        if($search->pageSize<1){
            $search->pageSize = 10;
        }
        $dataPage = $this->catelogService->search($search);
        $this->view->dataPage = $dataPage;
        $this->view->scriptClient = "var categories = " . json_encode($dataPage->data) . ';';
        $this->view->render('/catelog/grid');
    }

}
